class MonitorManager:
    def __init__(self, jenkins_manager):
        self.jenkins_manager = jenkins_manager
        self.scheduler = SchedulerService()

    def start_monitor(self, strategy_id: int):
        """启动监控"""
        strategy = TestStrategy.query.get(strategy_id)
        if not strategy:
            raise ValueError("Strategy not found")

        # 触发Jenkins构建
        build_number = self.jenkins_manager.trigger_build(
            'NVR_AUT',
            parameters={
                'DEVICE_NAME': strategy.device_model.model_name,
                'STRATEGY_ID': strategy_id
            }
        )

        # 更新策略状态
        strategy.is_monitoring = True
        strategy.current_build = build_number
        db.session.commit()

        return build_number

    def stop_monitor(self, strategy_id: int):
        """停止监控"""
        strategy = TestStrategy.query.get(strategy_id)
        if not strategy:
            raise ValueError("Strategy not found")

        strategy.is_monitoring = False
        db.session.commit() 